/*!
 * 面板控件.
 * ecp.qzz.ui.design.line.js
 * 创建：QZZ
 * 日期：2014-03-01
 */
define(["qzz.dbase"], function() {
	
	var qzz = window.qzz;
	qzz.space("ui.design");
	/**
	 * 面板控件.
	 */
	qzz.ui.design.line = qzz.Class(qzz.ui.design.base, {
		/**
		 * 创建函数
		 */
	    _create:function() {
	    	this.base();
            this.className = "Line";
            this.getOption().vertical = this.getBooleanValue(this.getOption().vertical, false);
            this.getOption().length = this._getNumberValue(this.getOption().length, 100);
            this.getOption().border = this._getNumberValue(this.getOption().border, 1);
            if(this.getOption().vertical) {
                this.getOption().width = 16;
                this.getOption().height = this.getOption().length;
            } else {
            	this.getOption().width = this.getOption().length;
                this.getOption().height = 16;
            }
            this._textAry = [];
	    },    
	    refresh:function() {
	    	this.base();
	    	var len = parseInt(this.getOption().length * this.getOption().scale);
	    	var vtc = this.getBooleanValue(this.getOption().vertical, false);
            if(vtc) {
    	    	this._setNumberValue(this.thisWindow, "borderTopWidth", 0);
    	    	this._setNumberValue(this.thisWindow, "borderBottomWidth", 0);
            	this._setNumberValue(this.thisWindow, "borderLeftWidth", 0);
            	this._setNumberValue(this.thisWindow, "borderRightWidth", this.getOption().border);
            	this._setNumberValue(this.thisWindow, "height", parseInt(this.getOption().length * this.getOption().scale, 10)); 
            	this._setNumberValue(this.thisWindow, "width", 16);
            	this._setNumberValue(this.thisWindow, "left", this.getOption().left - 16);
            } else {
    	    	this._setNumberValue(this.thisWindow, "borderTopWidth", 0);
    	    	this._setNumberValue(this.thisWindow, "borderBottomWidth", this.getOption().border);
    	    	this._setNumberValue(this.thisWindow, "borderLeftWidth", 0);
            	this._setNumberValue(this.thisWindow, "borderRightWidth", 0);
            	this._setNumberValue(this.thisWindow, "width", parseInt(this.getOption().length * this.getOption().scale, 10)); 
    	    	this._setNumberValue(this.thisWindow, "height", 16); 
    	    	//this._setNumberValue(this.thisWindow, "top", this.getOption().top - 16);
    	    	this.refreshTop();
            }
            
            var txt = this.getOption().text;
            this._setHtml(this.thisWindow, "", false);
            if(txt != null) {
            	var strLen = txt.length;
            	var avLen = parseInt(len/(strLen + 1), 10);
            	var txtLen = this._textAry.length;            	
            	for(var i = 0; i < strLen; i++) {
            		cstr = txt.charAt(i);
            		var step = (avLen * (i + 1)) + "px";
            		var spn = null;
            		if(i >= txtLen) {
            			spn = this.createElement("SPAN");  
            			spn.style.position = "absolute";
            			this._textAry.push(spn);            			
            		} else {
            			spn = this._textAry[i];
            		}
        			if(vtc) {
        				spn.style.top = step;
            			spn.style.right = "2px";
            			spn.style.left = "";
        			} else {            				
            			spn.style.top = "1px";
            			spn.style.left = step;
            			spn.style.right = "";
        			}
        			this._setHtml(spn, cstr);
            		this.thisWindow.appendChild(spn);
            	}
            	this.thisWindow.style.color = this.getOption().borderColor;
            }
	    },	    
	    getHeight:function() {
	    	var h = this.base();
	    	if(this.getOption().vertical) {
	    		return this.getOption().length;
	    	} else {
	    		return h + 16;
	    	}
	    },
	    getAttribute:function() {
	    	var attr = this.base();
	    	attr.push({"name":"length","value":this.getOption().length});
	    	attr.push({"name":"text","value":this.getOption().text});
	    	attr.push({"name":"borderStyle","value":this.getOption().borderStyle});
	    	attr.push({"name":"vertical","value":this.getOption().vertical});
	    	attr.splice(2, 2);
	    	return attr;
	    },
	    refreshTop:function() {
	    	this.base();
	    	this.getOption().vertical = this.getBooleanValue(this.getOption().vertical, false);
	    	var otop = this._getNumberValue(this.thisWindow.style.top, this.getOption().top);
	    	if(!this.getOption().vertical) {
	    	    this._setNumberValue(this.thisWindow, "top", otop - 16);
	    	}
	    }
	});
	
	/**
	 * 直线控件.
	 */
	_bindRenderFunc("qzzline", qzz.ui.design.line);
	return qzz.ui.design.line;
});